#include "multiply_op.h"
#include "../../factory/factory.h"
#include "../../factory/multiply_factory.h"

Multiply::Multiply(Node* lhs, Node* rhs) : OpNode({lhs, rhs}){
}

vector<Node*> Multiply::getGradNodes(Node* grad){
    auto nodes = *getNodeIn();
    Factory* factory;
    factory = new MultiplyFactory(grad, nodes[1]);
    Node* l_grad = factory -> createNode();
    delete factory;
    factory = new MultiplyFactory(grad, nodes[0]);
    Node* r_grad = factory -> createNode();
    delete factory;
    return {l_grad, r_grad};
}

void Multiply::compute(Context* context){
    auto nodes = *getNodeIn();
    context -> setFlowedData(this,
            context -> getFlowedData(nodes[0]) * context -> getFlowedData(nodes[1]));
}
